<template>
  <div class="masOrder">
    <!-- 短信变动页面 -->
    <!-- 搜索部分 -->
    <div class="search">
      <el-col :span="4" :offset="18">
        <el-input
          v-model="search"
          size="mini"
          placeholder="输入订单号/店铺id/店铺名称"
          clearable
          @keyup.enter.native="handleSearch"
        ></el-input>
      </el-col>
      <el-button
        size="mini"
        type="primary"
        @click="handleSearch"
        style="padding: 8px 20px;margin-left: 10px;border: none;color: #626366;background-color: #f1f1f1"
      >搜索</el-button>
    </div>
    <!-- 筛选部分 -->
    <div class="filtrate" style="display: none">
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="变动类型">
          <el-radio-group v-model="form.status" size="mini">
            <el-radio-button label="全部"></el-radio-button>
            <el-radio-button label="短信撤回"></el-radio-button>
            <el-radio-button label="短信回收"></el-radio-button>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="充值时间">
          <el-row>
            <el-col :lg="24" :xl="6">
              <el-radio-group v-model="form.payTime" size="mini">
                <el-radio-button label="全部"></el-radio-button>
                <el-radio-button label="今日"></el-radio-button>
                <el-radio-button label="近七天"></el-radio-button>
                <el-radio-button label="一个月内"></el-radio-button>
              </el-radio-group>
            </el-col>
            <el-col :span="6">
              <div class="block">
                <el-date-picker
                  v-model="form.payTime"
                  type="datetimerange"
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                  size="mini"
                ></el-date-picker>
              </div>
            </el-col>
            <el-col :span="2" :offset="10">
              <el-button type="primary" size="mini" @click="handleFiltrate" disabled>确定</el-button>
            </el-col>
          </el-row>
        </el-form-item>
      </el-form>
    </div>
    <!-- 表格部分 -->
    <div class="tableData">
      <el-table style="width: 100%;margin-bottom: 40px" :data="tableData">
        <el-table-column align="center" label="序号" type="index" width="50"></el-table-column>
        <el-table-column align="center" min-width="90" label="订单号">
          <template slot-scope="scope">
            <span>{{scope.row.sms_ordenum.substring(scope.row.sms_ordenum.length - 8)}}</span>
          </template>
        </el-table-column>
        <el-table-column align="center" min-width="90" label="店铺id" prop="user_id"></el-table-column>
        <el-table-column align="center" min-width="90" label="类型" prop="sms_mealname"></el-table-column>
        <el-table-column align="center" min-width="90" label="变动前数量" prop="sms_beforenum"></el-table-column>
        <el-table-column align="center" min-width="90" label="变动后数量" prop="sms_afternum"></el-table-column>
        <el-table-column align="center" label="变动数量" prop="sms_mealnum"></el-table-column>
        <el-table-column align="center" label="合计金额" prop="sms_mealprice"></el-table-column>
        <el-table-column
          align="center"
          min-width="160"
          :formatter="dateFormat"
          label="操作时间"
          prop="sms_mealdate"
        ></el-table-column>
        <el-table-column min-width="120" align="center" label="操作说明" prop="sms_mealpayment"></el-table-column>
      </el-table>
    </div>
    <!-- 这个是分页器 -->
    <Pagination
      :total="total"
      :pageIndex="pageIndex"
      :pageSize="pageSize"
      @handleSizeChange="handleSizeChange"
      @handleCurrentChange="handleCurrentChange"
    ></Pagination>
  </div>
</template>

<script>
import Pagination from "@/components/Pagination";
export default {
  data() {
    return {
      // 表单数据
      form: {
        status: "",
        payWay: "",
        payTime: ""
      },
      // 表格数据
      tableData: [],
      search: "",
      // 分页器的数据
      total: 0, // 总条数
      pageIndex: 1, // 当前页
      pageSize: 10, // 每页数量
      // 身份令牌
      myToken: ""
    };
  },
  components: { Pagination },
  methods: {
    init() {
      // 获取令牌
      this.myToken = sessionStorage.getItem("myToken");
      // 获取订单列表,初始化列表
      this.getOrderData();
    },
    // 获取订单数据的方法
    getOrderData() {
      this.$api
        .getMsmChangesOrderData(
          this.pageIndex,
          this.pageSize,
          this.search.trim(),
          this.myToken
        )
        .then(res => {
          this.total = res.total;
          this.tableData = res.dataList.map(v => {
            if (v.sms_mealname == "代理商为商户充值短信") {
              v.sms_mealname = "短信撤回";
            } else {
              v.sms_mealname = "短信回收";
            }
            return {
              ...v
            };
          });
        });
    },
    //时间格式化
    dateFormat: function(row, column) {
      var date = row[column.property];
      if (date == undefined) {
        return "";
      }
      return this.$moment(date).format("YYYY-MM-DD HH:mm:ss");
    },
    // 搜索的方法
    handleSearch() {
      this.pageIndex = 1;
      this.getOrderData();
    },
    // 分页器的方法
    handleSizeChange(val) {
      this.pageSize = val;
      this.getOrderData();
    },
    handleCurrentChange(val) {
      this.pageIndex = val;
      this.getOrderData();
    },
    // 筛选的方法
    handleFiltrate() {
      this.pageIndex = 1;
      this.getOrderData();
    }
  },
  mounted() {
    // 初始化函数
    this.init();
  }
};
</script>

<style lang="less" scoped>
@deep: ~">>>";
.masOrder {
  background-color: #fff;
  padding: 20px;
  .search {
    margin-bottom: 20px;
  }
  .filtrate {
    padding: 5px 10px;
    background-color: #f1f1f1;
    .el-radio-button {
      margin-right: 10px;
    }
  }
  // 表格表头
  .tableData @{deep} .el-table th {
    background-color: #fafafa;
    color: #252525;
    font-weight: 100;
  }
  // 弹出框的样式
  .recallDetail {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    .content {
      position: fixed;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      background-color: #fff;
      padding: 10px;
      box-sizing: border-box;
      border-radius: 10px;
    }
    .close {
      position: absolute;
      top: 10px;
      right: 10px;
      cursor: pointer;
      color: #666;
      font-size: 20px;
    }
  }
  // 筛选每一项
  .filtrate @{deep} .el-form-item {
    margin-bottom: 0;
  }
  // 筛选项的标题
  .filtrate @{deep} .el-form-item__label {
    color: #000;
    font-weight: 600;
  }
  // 筛选项的选项
  .filtrate @{deep} .el-radio-button__inner {
    border: 1px solid #f1f1f1;
    background-color: #f1f1f1;
    font-size: 14px;
    color: #626366;
  }
  // 筛选项的选中项
  .filtrate @{deep} .is-active .el-radio-button__inner {
    background-color: #f1f1f1;
    border: 1px solid #66b1ff;
    box-shadow: unset;
    color: #666;
    border-radius: 4px;
  }
}
</style>